/// <reference path="../Math/Rectangle.ts" />
/// <reference path="Unit.ts" />
module ew {
    export class RectangleUnit extends Unit {
        public color: string;
        public area: Rectangle;

        constructor(rectangle: Rectangle);
        constructor(rectangle: Rectangle, color: string);

        constructor(rectangle: Rectangle, color?: string) {
            super(new Vector2(rectangle.left, rectangle.top));
            this.area = rectangle;
            this.color = color != undefined ? color : "black";
        }

        public update(): void {
            super.update();
            this.area.location = this.position;
        }

        public draw(context: CanvasRenderingContext2D): void {
            context.save();
            context.fillStyle = this.color;
            context.translate(this.position.x, this.position.y);
            context.rotate(this.rotation);
            context.translate(-this.position.x, -this.position.y);
            context.fillRect(this.position.x, this.position.y, this.area.width, this.area.height);

            context.restore();
        }
    }
}